// 冒泡排序

let bubble = (arr) => {
  if (!Array.isArray(arr)) return `这不是一个数组`
  if (arr.length < 1) return []
  let num = 0
  for (let i = 0; i < arr.length; i++) {
    for (let l = num; l < arr.length; l++) {
      if (i !== l) {
        if (arr[i] > arr[l]) {
          [arr[i], arr[l]] = [arr[l], arr[i]]
        }
      }
    }
    num++
  }
  return arr
}

let arr = [1, 341, 1, 31, 3, 67, 7, 4]
console.time()
bubble(arr)
console.timeEnd()


console.time()
arr.sort((a, b) => a - b)
console.timeEnd()
